//
//  JHHomeViewController.swift
//  Weibo_SwiftDemo
//
//  Created by gjh on 2020/12/21.
//

import UIKit

private let cellID = "cellID"

class JHHomeViewController: JHBaseViewController {

    // 列表视图模型
    private lazy var statusListViewModel = JHStatusListViewModel()
    
    // 加载数据
    override func loadData() {
        
        statusListViewModel.loadStatus(pullUp: isPull) { (isSuccess, isShouldRefresh) in
            print("加载数据结束")
            self.isPull = false
            self.refreshControl?.endRefreshing()
            if isShouldRefresh {
                self.tableView?.reloadData()                
            }
        }
    }
    
    // 重写父类方法
    override func setupTableView() {
        super.setupTableView()
        title = "首页"
        naviItem.leftBarButtonItem = UIBarButtonItem(title: "好友", titleColor: UIColor.darkGray, highlightColor: UIColor.orange, target: self, action: #selector(showFriendClick), isback: false)
        
        tableView?.register(UITableViewCell.self, forCellReuseIdentifier: cellID)
    }
    // 点击方法
    @objc private func showFriendClick() {
        print(#function)
        
        let VC = NewsViewController()
        navigationController?.pushViewController(VC, animated: true)        
    }
}
// MARK: - 表格数据源方法
extension JHHomeViewController {
    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return statusListViewModel.statusList.count
    }
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        // 取 cell
        let cell = tableView.dequeueReusableCell(withIdentifier: cellID)
        
        // 设置 cell
        cell?.textLabel?.text = statusListViewModel.statusList[indexPath.row].text
        // 返回 cell
        return cell!
    }
}
